/**
 * @description elem to html
 * @author wangfupeng
 */

import { SlateElement } from '@wangeditor/editor';
import { MentionElement } from '../custom-types';

// 生成 html 的函数
function mentionToHtml(elem: SlateElement, childrenHtml: string): string {
  // console.log('mentionToHtml', elem);
  const { value = '', info = {}, url = '', typeLink = '', target = '' } = elem as MentionElement;
  const infoStr = encodeURIComponent(JSON.stringify(info));
  return `<a class="w-e-textarea-mention" data-w-e-type="mention" data-w-e-is-void data-w-e-is-inline data-value="${value}" data-info="${infoStr}" href="${url}" data-href="${url}" data-typeLink="${typeLink}" data-target="${target}">${value}</a>`;
}

// 配置
const conf = {
  type: 'mention', // 节点 type ，重要！！！
  elemToHtml: mentionToHtml,
};

export default conf;
